package vision;

import scene.Facette3D;

/**
 * This class represents a discrete(pixelized) facet. It's responsible for the
 * whole discretization process, that is take a projected facet with points with
 * real valeus and discretize it.
 * 
 */
public class ImageFacette implements Comparable<ImageFacette> {
	int[] pixelVertex1, pixelVertex2, pixelVertex3;
	private Double altitude;
	static int c = 0;

	/**
	 * Constructor for a ImageFacette(discrete Facette)
	 * 
	 * @param facette
	 *            the Facette3D to be discretized
	 * @param pixelSize
	 *            the pixel size to be used in the discretization process
	 */
	public ImageFacette(Facette3D facette, double pixelSize) {
		altitude = facette.getAltitude();
		pixelVertex1 = new int[2];
		pixelVertex2 = new int[2];
		pixelVertex3 = new int[2];
		associatePixel(facette, pixelSize);
	}

	private void associatePixel(Facette3D facette, double pixelSize) {
		// divide all coordinates by pixelSize
		// and round to the nearest integer
		pixelVertex1[0] = (int) Math.rint(facette.getVertex(1).getXCartesien()
				/ pixelSize);
		pixelVertex1[1] = (int) Math.rint(facette.getVertex(1).getYCartesien()
				/ pixelSize);

		pixelVertex2[0] = (int) Math.rint(facette.getVertex(2).getXCartesien()
				/ pixelSize);
		pixelVertex2[1] = (int) Math.rint(facette.getVertex(2).getYCartesien()
				/ pixelSize);

		pixelVertex3[0] = (int) Math.rint(facette.getVertex(3).getXCartesien()
				/ pixelSize);
		pixelVertex3[1] = (int) Math.rint(facette.getVertex(3).getYCartesien()
				/ pixelSize);
	}

	@Override
	public int compareTo(ImageFacette toBeCompared) {
		return altitude.compareTo(toBeCompared.altitude);
	}

	/**
	 * Get the X coordinates of the ImageFacette
	 * 
	 * @return the x coordinates
	 */
	public int[] getXPoints() {
		int[] xpoints = { pixelVertex1[0], pixelVertex2[0], pixelVertex3[0] };
		return xpoints;
	}

	/**
	 * Get the Y coordinate of the ImageFacette
	 * 
	 * @return the y coordinates
	 */
	public int[] getYPoints() {
		int[] ypoints = { pixelVertex1[1], pixelVertex2[1], pixelVertex3[1] };
		return ypoints;
	}
}
